package com.keith.brainmap.collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 将流转换成集合
 *
 * @author chenli
 * @date 2021-05-21 下午 04:30
 **/
public class CollectionStream {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("周杰伦");
        list.add("王力宏");
        list.add("陶喆");
        list.add("林俊杰");
        String[] arr = list.toArray(new String[0]);
        System.out.println(Arrays.toString(arr));

        List<Integer> ls1 = list.stream().map(String::length).collect(Collectors.toList());
        System.out.println(ls1);

        List<String> ls2 = list.stream().collect(Collectors.toCollection(ArrayList::new));
        System.out.println(ls2);

        String s = list.stream().collect(Collectors.joining(","));
        System.out.println(s);
    }
}
